package edu.hawaii.duedates.configuration;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.File;
import org.junit.Test;
import edu.hawaii.duedates.DueDates;

/**
 * Tests the Configuration Manger to see if it can obtain data and transmit it to the main class.
 * @author Creighton Okada
 *
 */
public class TestConfigurationManager {
  private static final String USER_DIR = "user.dir";
  /**
   * Reads in the xml configuration file and tests for correctness.
   */
  @Test
  public void testConfigurationManager() {
    File exampleDueDatesXml = new File(System.getProperty(USER_DIR) + "/xml/duedates.xml");
    File exampleDueDatesXsd = new File(System.getProperty(USER_DIR) + 
        "/xml/duedates.definition.xsd");
    ConfigurationManager manager = new ConfigurationManager(exampleDueDatesXml, exampleDueDatesXsd);
    DueDates dd = manager.getDueDates("test1@hawaii.edu", "test1now");
    //Tests to see if we have the right user
    String userName = dd.getUser().getName();
    assertEquals("Get user name.  Should return Test1.", userName, "Test1");
    //Tests to see user's library
    String userLib = dd.getLibraries().get(0).getName();
    assertEquals("Should have UH Library", userLib, "University of Hawaii");
  }
  
  /**
   * Tests the default constructor.
   */
  @Test
  public void testDefaultConstructor() {
    ConfigurationManager manager = new ConfigurationManager();
    assertEquals("Default constructor failed.", ConfigurationManager.class, manager.getClass());
  }
  
  /**
   * Tests return of null for incorrect login and password.
   */
  @Test
  public void testEmptyDueDates() {
    File exampleDueDatesXml = new File(System.getProperty(USER_DIR) + "/xml/duedates.xml");
    File exampleDueDatesXsd = new File(System.getProperty(USER_DIR) + 
        "/xml/duedates.definition.xsd");
    ConfigurationManager manager = new ConfigurationManager(exampleDueDatesXml, exampleDueDatesXsd);
    DueDates dd = manager.getDueDates("test1@hawaii.ude", "test1now");
    assertNull("dd should be null.", dd);
  }
}
